#yxh
from flask import Flask, jsonify, request, render_template
from flask_cors import CORS
#pip install flask-cors
import requests


app = Flask(__name__,template_folder='templates')
CORS(app)

students=[]


@app.route('/')
def index():
    return render_template('lunbo.html')

@app.route('/jq')
def jq():
    return render_template('jq.html')

@app.route('/jq3')
def jq3():
    return render_template('jq3.html')

@app.route('/xlcd')
def xlcd():
    return render_template('xlcd.html')

@app.route('/lx1') # 获取课程信息页面
def lx1():
    return render_template('7-1.html')

@app.route('/lx2') # 获取课程信息页面
def lx2():
    return render_template('7-2.html')

@app.route('/lx3') # 获取课程信息页面
def lx3():
    return render_template('7-3.html')

@app.route('/lx4') # 获取课程信息页面
def lx4():
    return render_template('7-4.html')

@app.route('/todolist')
def todolist():
    return render_template('todolist.html')

@app.route('/jquery') # 获取学生信息页面
def jquery():
    return render_template('jquery.html')

@app.route('/spider') # 获取学生信息页面
def spider():
    return render_template('spider.html')

@app.route("/proxy")
def proxy():
    target_url = request.args.get("url")
    response = requests.get(target_url)
    return response.content



@app.route('/ajax') # 获取学生信息页面
def ajax():
    url = "https://www.hceb.edu.cn/xwzx/mtjm.htm"
    source_code = ''
    try:
        response = requests.get(url)
        if response.status_code == 200:
            response.encoding = 'utf-8'
            source_code = response.text  # 将获取到的源代码存储到变量中         
        else:
            print("请求失败:", response.status_code)
    except Exception as e:
        print("发生异常:", e)

    return render_template('ajax.html', source_code=source_code)  # 将源代码传递给模板

import requests

@app.route('/ajax2')
def ajax2():
    url = "https://www.hceb.edu.cn/xwzx/mtjm.htm"
    source_code = ''
    try:
        response = requests.get(url)
        if response.status_code == 200:
            response.encoding = 'utf-8'
            source_code = response.text  # 将获取到的源代码存储到变量中         
        else:
            print("请求失败:", response.status_code)
    except Exception as e:
        print("发生异常:", e)

    return render_template('ajax2.html', source_code=source_code)  # 将源代码传递给模板


@app.route('/login', methods=['POST'])
def login():
    username = request.form['username']
    password = request.form['password']
    
    if username == "admin" and password == "123456":
        return jsonify({"success": True})
    else:
        return jsonify({"success": False})

@app.route('/yxh')
def yxh():
    return render_template('yxh.html')

@app.route('/event')
def event():
    return render_template('event.html')

@app.route('/list')
def list():
    return render_template('list.html')

@app.route('/Time')
def Time():
    return render_template('Time.html')

@app.route('/adv')
def adv():
    return render_template('adv.html')

@app.route('/store')
def store():
    return render_template('store.html')

@app.route('/addstu',methods=["post"])
def addstu():
    data = request.data.decode('utf-8')
    students.append(eval(data))
    print(students)
    return students

@app.route('/getstu')
def getstu():
    return students

@app.route('/promise')
def promise():
    return render_template('promise.html')


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=8011)
